/*****************************************************************************
 * steper.h
 *
 * Copyright (C) 2020 Jeasonvor 1101627719@qq.com
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 ****************************************************************************/
#ifndef __STEPER_H__
#define __STEPER_H__

/*****************************************************************************
 * Included Files
 ****************************************************************************/

/*****************************************************************************
 * Pre-processor Definitions
 ****************************************************************************/

/*****************************************************************************
 * Public Types
 ****************************************************************************/

typedef enum {
    STEPER_DIRECTION_POSITIVE, /** 正向    **/
    STEPER_DIRECTION_NEGATIVE, /** 反向    **/
} steper_direction_t;

typedef plum_s32 (*steper_read_t)(plum_u8 *rData, plum_u32 size,
                                  plum_u32 timeout);
typedef plum_s32 (*steper_write_t)(plum_u8 *rData, plum_u32 size);

/*****************************************************************************
 * Public Data
 ****************************************************************************/

/****************************************************************************/
#ifdef __cplusplus
extern "C" {
#endif
/*****************************************************************************
 * Public Function Prototypes
 ****************************************************************************/

/**
 * @brief:  步进电机初始化
 *
 * @param[in]:  read        -   读数据回调
 * @param[in]:  write       -   写数据回调
 *
 * @return: 返回执行状态
 */
plum_s32 dev_steper_init(steper_read_t read, steper_write_t write);

/**
 * @brief:  速度模式下运行
 *
 * @param[in]:  id              -       步进电机ID
 * @param[in]:  direction       -       方向
 * @param[in]:  speed           -       速度
 *
 * @return: 返回执行状态
 */
plum_s32 dev_steper_speed_run(plum_u32 id, steper_direction_t direction,
                              plum_u32 speed);

/**
 * @brief:  角度模式下运行
 *
 * @param[in]:  id              -       步进电机ID
 * @param[in]:  direction       -       方向
 * @param[in]:  angle           -       角度
 *
 * @return: 返回执行状态
 */
plum_s32 dev_steper_angle_run(plum_u32 id, steper_direction_t direction,
                              plum_float angle);

/**
 * @brief:  步进电机停止运行
 *
 * @param[in]:  id              -       步进电机ID
 *
 * @return: 返回执行状态
 */
plum_s32 dev_steper_stop(plum_u32 id);

/****************************************************************************/
#ifdef __cplusplus
}
#endif
/****************************************************************************/
#endif /* __STEPER_H__ */
/****************************************************************************/
/*                                                                          */
/*  End of file.                                                            */
/*                                                                          */
/****************************************************************************/
